package com.ruoyi.project.hcy.administrations.service.Impl;

import com.ruoyi.project.hcy.administrations.domain.Approve;
import com.ruoyi.project.hcy.administrations.domain.Dimission;
import com.ruoyi.project.hcy.administrations.mapper.ApproveMapper;
import com.ruoyi.project.hcy.administrations.mapper.DimissionMapper;
import com.ruoyi.project.hcy.administrations.service.IDimissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName DimissionServiceImpl
 * @Author 金刚芭比
 * @Date 2020/9/17 10:54
 * @Version 1.0
 */
@Service
public class DimissionServiceImpl implements IDimissionService {

    @Autowired
    private DimissionMapper dimissionMapper;
    @Autowired
    private ApproveMapper approveMapper;
    @Override
    public int insertDimission(Dimission dimission) {
        //设置默认值
        dimission.setDimissionType("离职申请");
        dimission.setDimissionStatus("待审批..");
        int insert = dimissionMapper.insertDimission(dimission);
        if (insert>0){
            Approve approve = new Approve();
            approve.setApproveName(dimission.getDimissionName());
            approve.setApproveTitle(dimission.getDimissionName()+"申请离职");
            approve.setApproveStatus(dimission.getDimissionStatus());
            approve.setApproveType(dimission.getDimissionType());
            approveMapper.insertApprove(approve);
        }
        return insert;
    }

    @Override
    public List<Dimission> selectDimissionAll(String dimissionType) {
        return dimissionMapper.selectDimissionAll(dimissionType);
    }

    @Override
    public int updateDimissionStatus(Dimission dimission) {
        return dimissionMapper.updateDimissionStatus(dimission);
    }

    @Override
    public Dimission selectDimissionByName(String dimissionName) {
        return dimissionMapper.selectDimissionBYName(dimissionName);
    }
}
